Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

171
Visualizações
Is there a simple way to add a variable string to an element attribute without "setAttribute"?

I'm trying to take data from another part of the element and add it to another (force lazy-loading images to load) and everything I find points me towards setAttribute however this breaks the data as it automatically adds a equals and quotations to the added data which breaks it.

So:

images[i].setAttribute('data-anim-src',' srcset= "'+images[i].getAttribute('data-srcset')+'"');

Gets me data-anim-src=" srcset="..."" instead of what I want which is data-anim-src srcset="..."

Is there any way to remove the ="" that's automatically added with setAttribute? or is there an equally simple alternative?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

setAttribute works like this:

setAttribute(attribute, value);

not like this:

setAttribute(attribute1, attribute2, attribute3);

So to solve it, just set them separately:

images[i].setAttribute('data-anim-src', 'true');
images[i].setAttribute('srcset', images[i].getAttribute('data-srcset'));
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda